﻿using System.Collections;
using System.Collections.Generic;
using IInject.Registration.Scanning;

namespace IInject
{
	public class ScanRules : IEnumerable<IScanningRule>
	{
		#region Fields

		private static volatile ScanRules Instance = new ScanRules();

		private readonly object _syncRoot = new object();
		private readonly List<IScanningRule> _conventions = new List<IScanningRule>
		{
            // Default conventions..
			ScanningRule.InterfaceNamingDefault(),
			ScanningRule.PublicClass()
		};

		#endregion

		#region Constructors

		static ScanRules()
		{
		}

		#endregion

		#region Properties

		public static ScanRules Current
		{
			get
			{
				return Instance;
			}
		}

		#endregion

		#region Methods

		public void Add(IScanningRule convention)
		{
			lock (_syncRoot)
			{
				_conventions.Add(convention);
			}
		}

		public void Clear()
		{
			lock (_syncRoot)
			{
				_conventions.Clear();
			}
		}

		public IEnumerator<IScanningRule> GetEnumerator()
		{
			lock (_syncRoot)
			{
				return _conventions.GetEnumerator();
			}
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		#endregion
	}
}
